<extend name="Common@Layout:layui" />
<block name="title">
    <title>权限管理</title>
</block>
<block name="style">
    <style>
        body {
            padding: 10px;
        }
        
        .layui-fixbar {
            display: none;
        }
        
        table {
            width: 100%;
            empty-cells: show;
            background-color: transparent;
            border-collapse: collapse;
            border-spacing: 0;
        }
        
        .table td {
            text-align: left;
        }
        
        .table th,
        .table td {
            padding: 8px;
            line-height: 20px;
        }
        
        .va-t {
            vertical-align: top!important;
        }
    </style>
</block>

<block name="main">
    <div style="padding:10px;background:#f8f8f8;margin-bottom:10px;">
        <form class="layui-form" id="change_group" action="{:U('rule')}" method="get">
            <div class="layui-form-item" style="margin-bottom:0;">
                <label class="layui-form-label">权限分组：</label>
                <div class="layui-input-inline">
                    <php>
                        $groups = C('AUTH_GROUP');
                    </php>
                    <select name="groupid" id="groupid" lay-filter="groupid" lay-filter="groupid" lay-verify="required" lay-search>
                        <option value="">请选择分组</option>
                        <foreach name="groups" item="vo" key="k">
                            <option value="{$k}" <if condition="$_GET['groupid'] eq $k">selected</if>>{$vo}</option>
                        </foreach>
                    </select>
                </div>
            </div>
        </form>
    </div>

    <table class="table">
        <tbody>
            <tr>
                <td width="200" class="va-t">
                    <div class="mb-10">
                        操作：
                        <div class="layui-btn-group" id="action-type-btns">
                            <button class="layui-btn layui-btn-danger" data-type="add">增加</button>
                            <button class="layui-btn" data-type="edit">编辑</button>
                            <button class="layui-btn" data-type="del">删除</button>
                        </div>
                    </div>
                    <ul id="catTree" style="margin-top:10px;"></ul>
                </td>
                <td class="va-t"><iframe id="catEditFrame" name="catEditFrame" frameborder="0" scrolling="AUTO" width="100%" height="490px" src="/admin/auth/rule_edit/group_id/{$_GET['groupid']}"></iframe></td>
            </tr>
        </tbody>
    </table>
</block>

<block name="script">
    <script>
        layui.use(['jquery', 'form'], function() {
            var form = layui.form;
            var $ = layui.jquery;
            var groupId = $('#groupid').val();
            form.on('select(groupid)', function(data) {
                if (data.value != groupId) {
                    $('#change_group').submit();
                }
            });
        });
        mini_callback();
        //提供给iframe回调的函数
        function mini_callback() {
            layui.use(['jquery', 'ruleadmin'], function() {
                var $ = layui.jquery;
                //console.log(layui.catadmin.loadTreeData);
                layui.ruleadmin.loadTreeData();
            });
        }
    </script>
</block>